package com.ayoka.ui.main;

import android.view.View;

import com.ayoka.R;
import com.ayoka.adapter.CommonPagerAdapter;
import com.ayoka.base.BaseFragment;
import com.ayoka.bean.CoursePackageBean;
import com.ayoka.databinding.FragmentHomeBinding;
import com.ayoka.mvp.HomeMVP.HomePresenter;
import com.ayoka.mvp.HomeMVP.IHomeView;
import com.ayoka.ui.course.course_package.CoursePackageEmptyFragment;
import com.ayoka.ui.course.course_package.CoursePackageFragment;
import com.ayoka.widget.ScaleTransformer;

import java.util.List;

/**
 * 首页的Fragment
 * <p>
 * Created by admin on 2017/3/22.
 */

public class HomeFragment extends BaseFragment<FragmentHomeBinding, HomePresenter> implements IHomeView {

    private CommonPagerAdapter collectionPageAdapter;

    @Override
    public int getContentLayout() {
        return R.layout.fragment_home;
    }

    @Override
    protected void initViews(View view) {
    }

    @Override
    public void initData() {
        mPresenter.getCoursePackageListData();
    }

    @Override
    protected HomePresenter getPresenter() {
        return new HomePresenter();
    }


    @Override
    public void configCoursePackageListData(List<CoursePackageBean> listData) {
        collectionPageAdapter = new CommonPagerAdapter(getChildFragmentManager());
        if (listData== null || listData.isEmpty()){
            CoursePackageEmptyFragment coursePackageEmptyFragment = CoursePackageEmptyFragment.newInstance();
            collectionPageAdapter.addFragment(coursePackageEmptyFragment, "空数据");
        } else {
            for (CoursePackageBean coursePackageBean : listData) {
                CoursePackageFragment coursePackageFragment = CoursePackageFragment.newInstance(coursePackageBean);
                collectionPageAdapter.addFragment(coursePackageFragment, coursePackageBean.PackageName);
            }
        }
        mDataBinding.viewPagerCourse.setAdapter(collectionPageAdapter);
//        // 由于使用带有阴影效果的背景图 所以margin要设置为负数才能达到效果
//        mDataBinding.viewPagerCourse.setPageMargin((int) UIUtils.getDimensionPixelSize(R.dimen.dp_m_16));
        mDataBinding.viewPagerCourse.setPageTransformer(true, new ScaleTransformer());
        mDataBinding.viewPagerCourse.setOffscreenPageLimit(3);
    }
}
